﻿Public Class MainForm
    ''' <summary>
    ''' 添加用户,弹出EditUser窗口
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim edit As New EditUser
        edit.Owner = Me
        edit.Show()
    End Sub
    ''' <summary>
    ''' 修改用户
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If DataGridView1.RowCount > 0 Then
            Dim ID As String
            ID = DataGridView1.CurrentRow.Cells("ID").Value
            ' MessageBox.Show("ID: " + ID)

            Dim edit As New EditUser
            edit.Owner = Me
            '隐藏添加按钮，显示修改按钮
            edit.Button1.Visible = False
            edit.Button2.Visible = True
          
            edit.InitData(ID)
            edit.Show()
        End If

    End Sub
    ''' <summary>
    ''' 删除用户
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim idList As New List(Of Integer)

        If DataGridView1.Rows.Count > 0 Then

            For index = 0 To DataGridView1.Rows.Count - 1
                If DataGridView1.Rows(index).Cells("ColumnCkeckBox").Value Then               
                    idList.Add(Convert.ToInt32(DataGridView1.Rows(index).Cells("ID").Value))
                End If           
            Next
            If idList Is Nothing Then
                MessageBox.Show("请选择要删除的对象")
            ElseIf MessageBox.Show("确定删除？", "警告 ", MessageBoxButtons.OK) = vbOK Then

                If UserBLL.DeleteUsers(idList) Then
                    MessageBox.Show("删除成功")
                    Me.SetDataGridView()

                Else
                    MessageBox.Show("删除失败")
                End If

            End If

           
        End If

    End Sub

    Public Sub SetDataGridView()
        Me.DataGridView1.DataSource = UserBLL.GetUserInfo


    End Sub

   
   
End Class
